package com.ch.ms.server.login;

import com.ch.ms.server.base.AbstractMapleServer;
import com.ch.ms.server.base.MaplePacketHandler;
import com.ch.ms.server.base.PingPacketHandler;
import com.ch.ms.server.login.packet.handler.LoadCharactersPacketHandler;
import com.ch.ms.server.login.packet.handler.LoginRequestPacketHandler;
import com.ch.ms.server.packet.*;
import io.netty.channel.ChannelHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
@Slf4j
public class MapleLoginServer extends AbstractMapleServer {


    private final LoginRequestPacketHandler loginRequestPacketHandler;


    private final LoadCharactersPacketHandler loadCharactersPacketHandler;

    @Autowired
    public MapleLoginServer(LoginRequestPacketHandler loginRequestPacketHandler, LoadCharactersPacketHandler loadCharactersPacketHandler) {
        this.loginRequestPacketHandler = loginRequestPacketHandler;
        this.loadCharactersPacketHandler = loadCharactersPacketHandler;
    }


    @Override
    public List<ChannelHandler> getChannelHandlers() {
        return null;
    }

    @Override
    public Map<MaplePacketHeader, Class<? extends MaplePacket>> getSupportedPackets() {
        return new HashMap<MaplePacketHeader, Class<? extends MaplePacket>>() {
            private static final long serialVersionUID = 8710457397655696459L;

            {
                put(MaplePacketHeader.PING, PingPacket.class);
                put(MaplePacketHeader.LOGIN, LoginRequestPacket.class);
                put(MaplePacketHeader.LOAD_CHARACTERS, LoadCharactersPacket.class);
            }
        };
    }


    @Override
    public Map<MaplePacketHeader, MaplePacketHandler> getPacketHandlers() {
        return new HashMap<MaplePacketHeader, MaplePacketHandler>() {
            private static final long serialVersionUID = 8710457397655696459L;

            {
                put(MaplePacketHeader.PING, PingPacketHandler.builder().build());
                put(MaplePacketHeader.LOGIN, loginRequestPacketHandler);
                put(MaplePacketHeader.LOAD_CHARACTERS, loadCharactersPacketHandler);
            }

        };
    }


    @Override
    public String getName() {
        return "冒险岛登录服务器";
    }
}
